package com.hqyj.controller;

import com.hqyj.dao.ClassesMapper;
import com.hqyj.pojo.Classes;
import com.hqyj.pojo.Teach;
import com.hqyj.pojo.TimeTable;
import com.hqyj.service.TeachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * <p></p>
 *
 * @author : X_jay
 * @date : 2020-09-01 17:26
 **/
@Controller
@RequestMapping("teach")
public class TeachController {
    @Autowired
    TeachService teachService;
    @Autowired
    ClassesMapper classesMapper;

    //课表页面
    @RequestMapping("timeTable")
    public String timeTable() {
        return "educational/timeTable";
    }
    //课表查询
    @RequestMapping("select")
    @ResponseBody
    public HashMap<String,Object> select(TimeTable table) {
        System.out.println("table = " + table);
        return teachService.selectTimeTable(table);
    }

    //跳转安排页面
    @RequestMapping("arrange")
    public String arrange() {
        return "educational/teachPlan";
    }

    //课程安排
    @RequestMapping("add")
    @ResponseBody
    public HashMap<String,Object> add(Teach teach) {
        System.out.println("teach ====================================================================== " + teach);
        return teachService.add(teach);
    }
    //班级查询
    @RequestMapping("selectClass")
    @ResponseBody
    public HashMap<String,Object> selectClass() {
        return teachService.selectClass();
    }

    //课程查询
    @RequestMapping("courList")
    @ResponseBody
    public HashMap<String,Object> courList(Long clId) {
        return teachService.selectCource(clId);
    }
    //课程查询
    @RequestMapping("courListByName")
    @ResponseBody
    public HashMap<String,Object> courListByName(String clName) {
        Classes classes = classesMapper.selectByClaName(clName);
        return teachService.selectCource(classes.getClId());
    }

    //老师查询
    @RequestMapping("teacherList")
    @ResponseBody
    public HashMap<String,Object> teacherList() {
        return teachService.selectTeacherList();
    }
    //教室查询
    @RequestMapping("roomList")
    @ResponseBody
    public HashMap<String,Object> roomList() {
        return teachService.selectroomList();
    }

    @RequestMapping("update")
    @ResponseBody
    public HashMap<String,Object> update(String clName,Teach record) {
        Classes classes = classesMapper.selectByClaName(clName);
        record.setClId(classes.getClId());
        record.setIsDelete(0);
        return teachService.updateByTeach(record);
    }

    @RequestMapping("del")
    @ResponseBody
    public HashMap<String,Object> del(Long skId) {
        return teachService.deleteBySkId(skId);
    }
}
